package jmu.cze.service.impl;

import jmu.cze.mapper.UserMapper;
import jmu.cze.pojo.Customer;
import jmu.cze.pojo.User;
import jmu.cze.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserServiceImpl implements UserService {

    @Resource(name = "userMapper")
    private UserMapper userMapper;

    @Override
    public boolean deleteUser(String userID) {
        userMapper.deleteCustomer(userID);
        return userMapper.deleteUser(userID)==1;
    }

    @Override
    public boolean insertUser(User user) {
        return userMapper.insertUser(user)==1;
    }

    @Override
    public boolean insertCustomer(Customer customer) {
        return userMapper.insertUser(customer.getUser())==1 && userMapper.insertCustomer(customer)==1;
    }

    @Override
    public User selectUser(String userID) {
        return userMapper.selectUser(userID);
    }

    @Override
    public Customer selectCustomer(String userID) {
        return userMapper.selectCustomer(userID);
    }

    @Override
    public boolean update(User user) {
        return userMapper.updateUser(user)==1;
    }

    @Override
    public boolean update(Customer customer) {
        return update(customer.getUser()) && userMapper.updateCustomer(customer)==1;
    }
}
